package cn.zyzpp.service.resume.impl;

import cn.zyzpp.dao.SkillsHobbyDao;
import cn.zyzpp.entity.resume.SkillsHobby;
import cn.zyzpp.service.resume.SkillsHobbyService;
import cn.zyzpp.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

/**
 * Create by yster@foxmail.com 2018/5/21/021 23:00
 */
@Service
@CacheConfig(cacheNames = {"SkillsHobbyService"})
public class SkillsHobbyServiceImpl implements SkillsHobbyService {
    @Autowired
    private SkillsHobbyDao skillsHobbyDao;

    @Override
    @CacheEvict(allEntries = true)
    public void save(SkillsHobby skillsHobby, int uid) {
        skillsHobby.setUid(uid);
        skillsHobby.setState(StringUtil.symline(skillsHobby.getState()));
        skillsHobbyDao.save(skillsHobby);
    }

    @Override
    @Transactional
    @CacheEvict(allEntries = true)
    public void delect(int id) {
        skillsHobbyDao.deleteAllById(id);
    }

    @Override
    @Transactional
    @CacheEvict(allEntries = true)
    public void updataByUid(SkillsHobby skillsHobby) {
        SkillsHobby skillsHobby1 = skillsHobbyDao.findByUid(skillsHobby.getUid());
        skillsHobby.setState(StringUtil.symline(skillsHobby.getState()));
        skillsHobby1.updata(skillsHobby);
    }

    @Override
    @Cacheable(key = "targetClass + methodName +#p0")
    public SkillsHobby query(int uid) {
        return skillsHobbyDao.findByUid(uid);
    }

    @Override
    @Cacheable(key = "targetClass + methodName +#p0")
    public List<SkillsHobby> queryAll(int uid) {
        return skillsHobbyDao.findAllByUid(uid);
    }
}
